<?php
include "./Lib/DBMySql.inc";
include "./Lib/Common.php";
include "./Entities/viewclicksObj.php";
include "./DAL/viewclicksDAL.php";

$mainDB = NewDB(DATABASE_HOST, DATABASE_NAME , DATABASE_USER, DATABASE_PASSWORD);

$ip = $_SERVER["REMOTE_ADDR"];

$viewClickObj = new viewclicksObj();

$viewclicks = viewclicksDAL::GetList($mainDB, "ip='$ip' AND pagePositionID='$pagePositionID' AND bannerID='$bannerID' AND DATE(now())='".date('Y-m-d')."'", "", "", $errorPage);
if ($viewclicks!=null && count($viewclicks)>0)
{
	$viewClickObj = $viewclicks[0];	
	$viewClickObj->viewTimes += 1;
	viewclicksDAL::Update($mainDB, $viewClickObj, $errorPage);
}
else
{
	$viewClickObj->viewTimes = 1;
	$viewClickObj->clickTimes = 0;
	$viewClickObj->bannerID = $bannerID;
	$viewClickObj->issueDate = date("Y-m-d 00:00:00");
	$viewClickObj->ip = $ip;
	$viewClickObj->pagePositionID = $pagePositionID;
	
	viewclicksDAL::Insert($mainDB, $viewClickObj, $errorPage);
	//echo $errorPage;
}
?>